package com.topisv.tms.rest.qimen.util.goodsinfo;

import com.topisv.tms.entity.EdiGoodsSku;
import com.topisv.tms.rest.qimen.qmentity.request.goodsinfo.EdiGoodsSkuVo;
import com.topisv.tms.rest.qimen.qmentity.request.goodsinfo.GoodsActionType;
import com.topisv.tms.rest.qimen.qmentity.request.goodsinfo.SingleGoodsInfo;
import com.topisv.tms.rest.qimen.qmentity.request.goodsinfo.SingleGoodsInfoItem;
import com.topisv.tms.utils.BlankUtil;
import com.topisv.tms.utils.WmsContants;

/**
 * 对象转换
 *  Date          Author       Version       Description
 * ----------------------------------------------------------
 *  2015-5-6      CC            1.0           Create
 */
public class TransferHelper {

	public static EdiGoodsSkuVo toEdiGoodsSku(SingleGoodsInfo goodsInfo,EdiGoodsSku dbData) {
		EdiGoodsSkuVo vo = new EdiGoodsSkuVo();
		EdiGoodsSku goodsSku = dbData == null ? new EdiGoodsSku() : dbData;
		goodsSku.setCustomerCode(goodsInfo.getOwnerCode());
		
		SingleGoodsInfoItem goodsInfoItem = goodsInfo.getItem();
		goodsSku.setBar(goodsInfoItem.getItemCode());
		goodsSku.setSkuName(goodsInfoItem.getItemName());
		/*String[] sku = goodsInfoItem.getBarCode().split(";");
		goodsSku.setSku(sku[sku.length-1]);*/
		if(GoodsActionType.UPDATE.getType().equals(goodsInfo.getActionType())&&"ADL".equals(goodsInfo.getOwnerCode()))
		{
			//goodsSku.setSku(goodsSku.getSku());
		}
		else
		{
			String[] sku = goodsInfoItem.getBarCode().split(";");
			goodsSku.setSku(sku[sku.length-1]);
		}

		goodsSku.setSpec(goodsInfoItem.getSkuProperty());
		goodsSku.setUnit(goodsInfoItem.getStockUnit());
		goodsSku.setLen(goodsInfoItem.getLength());
		goodsSku.setWid(goodsInfoItem.getWidth());
		goodsSku.setHei(goodsInfoItem.getHeight());
		goodsSku.setVol(goodsInfoItem.getVolume());
		goodsSku.setNwt(goodsInfoItem.getGrossWeight());
		goodsSku.setGwt(goodsInfoItem.getNetWeight());
		goodsSku.setCol(goodsInfoItem.getColor());
		goodsSku.setSiz(goodsInfoItem.getSize());
		goodsSku.setItemType(goodsInfoItem.getItemType());
		goodsSku.setTagPrice(goodsInfoItem.getTagPrice());
		goodsSku.setUnitPrice(goodsInfoItem.getCostPrice());
		goodsSku.setBrandCode(goodsInfoItem.getBrandCode());
		goodsSku.setBrandName(goodsInfoItem.getBrandName());
		goodsSku.setDes(goodsInfoItem.getRemark());
		goodsSku.setIsShelfLifeMgmt(BlankUtil.isBlank(yes2One(goodsInfoItem.getIsShelfLifeMgmt()), "0"));
		goodsSku.setShelfLife(goodsInfoItem.getShelfLife());
		goodsSku.setIsBatchMgmt(BlankUtil.isBlank(yes2One(goodsInfoItem.getIsBatchMgmt()), "0"));
		goodsSku.setIsFragile(BlankUtil.isBlank(yes2One(goodsInfoItem.getIsFragile()), "0"));
		goodsSku.setIsHazardous(BlankUtil.isBlank(yes2One(goodsInfoItem.getIsHazardous()), "0"));
		goodsSku.setIsValid(BlankUtil.isBlank(yes2One(goodsInfoItem.getIsValid()), "1"));
		goodsSku.setCreateTime(goodsInfoItem.getCreateTime());
		goodsSku.setUpdateTime(goodsInfoItem.getUpdateTime());
		goodsSku.setSafetyStock(goodsInfoItem.getSafetyStock());
		goodsSku.setAdventLifecycle(goodsInfoItem.getAdventLifecycle());
		goodsSku.setLockupLifecycle(goodsInfoItem.getLockupLifecycle());
		goodsSku.setRejectLifecycle(goodsInfoItem.getRejectLifecycle());
		
		vo.setGoodsSku(goodsSku);
		return vo;
	}

	public static Integer kg2g(Double kg) {
		return kg == null ? null : Double.valueOf((kg * 1000)).intValue();
	}

	public static String yes2One(String s) {
		return WmsContants.YES.equalsIgnoreCase(s) ? "1" : WmsContants.NO.equalsIgnoreCase(s) ? "0" : null;
	}
}
